package gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

import card.Card;

/**
 * 
 * @author antongr
 * Similar to the GUITile. Can be linked to Cards and is drawn by CenterPanel.
 */
public class SelectionSphere {

	/**
	 * Point for center of the sphere, seen as screen pixel coordinates.
	 */
	protected Point pos;
	protected Card card;
	protected boolean highlighted=false;
	protected int size = GUIConstants.TILESIZE;
	
	public SelectionSphere(Card c){
		card=c;
	}
	
	public void setSize(int i){
		size = i;
	}
	
	public void paint(Graphics g){
		if(card != null)
			ImageHandler.getInstance().drawImage(pos.x-size/2, pos.y-size/2, size, size, card.getImageSmall(), g);
		if(highlighted){		
			g.setColor(Color.green);
			g.drawOval(pos.x-size/2, pos.y-size/2, size, size);
		}
	}
	
	/**
	 * Returns true if the given screen coordinates fall within the sphere
	 * @param x
	 * @param y
	 * @return
	 */
	public boolean contains(int x, int y){
		if( Math.sqrt(Math.pow(pos.x-x,2)+Math.pow(pos.y-y,2)) < size/2)
			return true;
		else
			return false;
	}
	
	/**
	 * Sets the center of the sphere to the given Point
	 * @param p
	 */
	public void setPosition(Point p){
		pos=p;
	}
	/**
	 * Gives the sphere a position in an arc around the given centerPoint.
	 * @param centerPoint
	 * @param amountOfSpheres
	 * @param idOfThisSphere
	 */
	public void setPosition(Point centerPoint, int amountOfSpheres, int idOfThisSphere){
		double angle = (double)idOfThisSphere-2.5;
		int rangeFromCenter=GUIConstants.TILESIZE+idOfThisSphere*5;
		int x=centerPoint.x+(int)(Math.cos(angle)*rangeFromCenter);
		int y=centerPoint.y+(int)(Math.sin(angle)*rangeFromCenter);
		pos=new Point(x, y);
		
	}
	public Card getCard(){
		return card;
	}
	/**
	 * purely visual effect
	 * @param h
	 */
	public void setHighlighted(boolean h){
		highlighted = h;
	}
}
